package com.waterdrop.wlsggk.service.impl;


import com.waterdrop.wlsggk.mapper.DishMaterialMapper;
import com.waterdrop.wlsggk.pojo.DishMaterial;
import com.waterdrop.wlsggk.service.DishMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 菜品物料信息 服务层处理
 *
 * @author ruoyi
 */
@Service
public class DishMaterialServiceImpl implements DishMaterialService {

    @Autowired
    private DishMaterialMapper dishMaterialMapper;

    /**
     * 查询菜品物料数据集合
     *
     * @param dishMaterial 菜品物料信息
     * @return 菜品物料数据集合
     */
    @Override
    public List<DishMaterial> selectWlsggkDishMaterialList(DishMaterial dishMaterial) {
        return dishMaterialMapper.selectWlsggkDishMaterialList(dishMaterial);
    }

    /**
     * 根据菜品id，删除菜品物料信息
     *
     * @param ids 菜品ID
     * @return 结果
     */
    @Override
    public int deleteWlsggkDishMaterial(Long[] ids) {
        return dishMaterialMapper.deleteWlsggkDishMaterialByIds(ids);
    }


    /**
     * 根据菜品id查询菜品物料信息
     *
     * @param id 菜品ID
     * @return 结果
     */
    @Override
    public List<DishMaterial> selectWlsggkDishMaterialByDishId(Long id) {

        return dishMaterialMapper.selectWlsggkDishMaterialByDishId(id);
    }

    /**
     * 添加保存菜品物料
     *
     * @param dishMaterial 菜品物料信息
     * @return 结果
     */
    @Override
    public int insertWlsggkDishMaterial(List<DishMaterial> dishMaterial) {
        List<Integer> insertResults = new ArrayList<>();
        for (DishMaterial dishMaterial1 : dishMaterial) {
            int insertResult = dishMaterialMapper.insertWlsggkDishMaterial(dishMaterial1);
            insertResults.add(insertResult);
        }
        Set<Integer> set = new HashSet<>(insertResults);
        return (set.size() == 1) ? 1 : 0;
    }

    /**
     * 修改菜品物料
     *
     * @param dishMaterial 菜品物料信息
     * @return 结果
     */
    @Override
    public int updateWlsggkDishMaterial(DishMaterial dishMaterial) {
        return dishMaterialMapper.updateWlsggkDishMaterial(dishMaterial);
    }
}


